package com.octopus.media;

import android.app.Application;
import android.content.pm.PackageManager;
import android.os.Environment;

import java.io.File;

public class App extends Application {

    @Override
    public void onCreate() {
        // 程序创建的时候执行
        super.onCreate();

        initFile();
    }

    private void initFile(){
        PackageManager pm = getPackageManager();
        boolean permission_readStorage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.READ_EXTERNAL_STORAGE", "com.octopus.media"));
        boolean permission_writeStorage = (PackageManager.PERMISSION_GRANTED == pm.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", "com.octopus.media"));

        if (!permission_readStorage || !permission_writeStorage) return;

        try {
            File sdDir = Environment.getExternalStorageDirectory();
            if (sdDir == null) return;
            File YjrMedia = new File(sdDir+"/YjrMedia");
            if(YjrMedia != null){
                if (!YjrMedia.exists()){
                    YjrMedia.mkdir();
                }
            }
            File videos = new File(sdDir+"/YjrMedia/videos");
            if(videos != null){
                if (!videos.exists()){
                    videos.mkdir();
                }
            }
            File apks = new File(sdDir+"/YjrMedia/apks");
            if(apks != null){
                if (!apks.exists()){
                    apks.mkdir();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
